#version 110

varying vec3 LightDir;
varying vec2 TexCoord;
varying vec3 ViewDir;

uniform sampler2D Tex1;
uniform sampler2D NormalMapTex;

uniform vec4 LightPosition;
uniform vec3 LightIntensity;

uniform vec3 Ka;				// Ambient reflectivity
uniform vec3 Kd;				// Diffuse reflectivity
uniform vec3 Ks;				// Specular reflectivity
uniform float Shininess;	

vec3 phongModel( vec3 norm, vec3 diffR ) {
vec3 r = reflect( -LightDir, norm );
vec3 ambient =  Ka;
float sDotN = max( dot(LightDir, norm), 0.0 );
vec3 diffuse =  diffR * sDotN;
vec3 spec = vec3(0.0) * LightIntensity;
if( sDotN > 0.0 )
spec = Ks *
pow( max( dot(r,ViewDir), 0.0 ),Shininess );
return ambient + diffuse + spec;

}

void main() {
vec4 normal = texture2D( NormalMapTex, TexCoord );
vec4 texColor = texture2D( Tex1, TexCoord );
gl_FragColor = vec4( phongModel(vec3(normal), vec3(texColor)),1.0 );
//gl_FragColor = vec4(LightIntensity, 1.0);
////////////////////////////////////


// Extract the normal from the normal map  
//vec3 normal = normalize(texture2D(NormalMapTex, TexCoord).rgb * 2.0 - 1.0);  
  
// Determine where the light is positioned (this can be set however you like)  
//vec3 light_pos = normalize(vec3(1.0, 1.0, 1.5));  
  
// Calculate the lighting diffuse value  
//float diffuse = max(dot(normal, light_pos), 0.0);  
  
//vec3 color = diffuse - texture2D(Tex1, TexCoord).rgb;  
  
// Set the output color of our current pixel  
//gl_FragColor = vec4(color, 1.0);  


}
